package com.esdk.log;
import com.esdk.utils.Constant;

import java.io.IOException;
import java.io.OutputStream;
public class ConsoleAppender extends AbstractAppender{
  private OutputStream _infoOutStream;
  private OutputStream _errOutStream;
  
  public ConsoleAppender(){
    _infoOutStream=System.out;
    _errOutStream=System.err;
  }

  public void append(ILogItem item){
    if(item!=null){
      try{
        if(item.getLevel().getLevel()==DefaultLogLevel._DEBUG)
          _infoOutStream.write((Constant.CYAN+item.getResult()+Constant.RESET).getBytes());
        else if(item.getLevel().getLevel()==DefaultLogLevel._INFO)
          _infoOutStream.write(item.getResult().getBytes());
        else if(item.getLevel().getLevel()==DefaultLogLevel._WARN)
          _infoOutStream.write((Constant.YELLOW_HIGH+item.getResult()+Constant.RESET).getBytes());
        else
          _errOutStream.write(item.getResult().getBytes());
      }
      catch(IOException e){
        e.printStackTrace();
      }
    }
  }

  public static void main(String[] args){}

}
